﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FinalTestMachine.Connect;

namespace FinalTestMachine.View.MainUnits
{
    /// <summary>
    /// Unit_ResultList.xaml 的交互逻辑
    /// </summary>
    public partial class Unit_ResultList : UserControl
    {
        public Unit_ResultList()
        {
            InitializeComponent();

            /*lv_Sit1Station.ItemsSource = Site1_Data;
            lv_Sit2Station.ItemsSource = Site2_Data;
            lv_Sit3Station.ItemsSource = Site3_Data;
            lv_Sit4Station.ItemsSource = Site4_Data;*/

            for(int i = 0; i < GlobalParams.WorkstationSum; i++)
            {
                ObservableCollection<UdpItemData> SiteData = new ObservableCollection<UdpItemData>();
                stationResultList.Add(SiteData);
            }
            //test();

        }

        void test()
        {
            UdpItemData udpItemData = new UdpItemData();
            udpItemData.Name = "Test";
            udpItemData.Value = "A";
            udpItemData.Result = "OK";
            udpItemData.bdBrush = Brushes.Green;
            AddSiteXData(4, new List<UdpItemData>() { udpItemData });
        }
        public List<ObservableCollection<UdpItemData>> stationResultList = new List<ObservableCollection<UdpItemData>>();

        /*ObservableCollection<UdpItemData> Site1_Data = new ObservableCollection<UdpItemData>();
        ObservableCollection<UdpItemData> Site2_Data = new ObservableCollection<UdpItemData>();
        ObservableCollection<UdpItemData> Site3_Data = new ObservableCollection<UdpItemData>();
        ObservableCollection<UdpItemData> Site4_Data = new ObservableCollection<UdpItemData>();*/

        public void Clear()
        {
            foreach (var item in stationResultList)
            {
                item.Clear();
            }
        }

        /// <summary>
        /// 给指定工站添加测试数据
        /// </summary>
        /// <param name="index">工站号</param>
        /// <param name="siteData">测试数据</param>
        public void AddSiteXData(int index, List<UdpItemData> siteData) {
            index--;
            if (index >= GlobalParams.WorkstationSum) {
                return;
            }
            this.Dispatcher.Invoke(() => {
                stationResultList[index].Clear();
                if (siteData != null && siteData.Count != 0) {
                    siteData.ForEach(item => { stationResultList[index].Add(item); });
                }
            });
        }

        /*/// <summary>
        /// 添加工位2的数据显示
        /// </summary>
        /// <param name="udpItemDatas"></param>
        public void AddSite1_Data(List<UdpItemData> udpItemDatas)
        {
            this.Dispatcher.Invoke(() =>
            {
                Site1_Data.Clear();
                if (udpItemDatas == null) return;
                if (udpItemDatas.Count == 0) return;
                foreach (var item in udpItemDatas)
                {
                    Site1_Data.Add(item);
                }

            });
        }

        /// <summary>
        /// 添加工位2的数据显示
        /// </summary>
        /// <param name="udpItemDatas"></param>
        public void AddSite2_Data(List<UdpItemData> udpItemDatas)
        {
            this.Dispatcher.Invoke(() =>
            {
                Site2_Data.Clear();
                if (udpItemDatas == null) return;
                if (udpItemDatas.Count == 0) return;
                foreach (var item in udpItemDatas)
                {
                    Site2_Data.Add(item);
                }

            });
        }


        /// <summary>
        /// 添加工位3的数据显示
        /// </summary>
        /// <param name="udpItemDatas"></param>
        public void AddSite3_Data(List<UdpItemData> udpItemDatas)
        {
            this.Dispatcher.Invoke(() =>
            {
                Site3_Data.Clear();
                if (udpItemDatas == null) return;
                if (udpItemDatas.Count == 0) return;
                foreach (var item in udpItemDatas)
                {
                    Site3_Data.Add(item);
                }

            });
        }

        /// <summary>
        /// 添加工位4的数据显示
        /// </summary>
        /// <param name="udpItemDatas"></param>
        public void AddSite4_Data(List<UdpItemData> udpItemDatas)
        {
            this.Dispatcher.Invoke(() =>
            {
                Site4_Data.Clear();
                if (udpItemDatas == null) return;
                if (udpItemDatas.Count == 0) return;
                foreach (var item in udpItemDatas)
                {
                    Site4_Data.Add(item);
                }

            });
        }*/
    }
}
